//
//  ToolExtension.swift
//  AzaanSwift
//
//  Created by Azzan on 2018/3/10.
//  Copyright © 2018年 Azzan. All rights reserved.
//

import UIKit
import CoreImage

let KScreenW = UIScreen.main.bounds.size.width
let KScreenH = UIScreen.main.bounds.size.height

extension UIColor {
    
    static func rgb(_ r: CGFloat, _ g: CGFloat, _ b: CGFloat) -> UIColor {
        return UIColor.init(red: r / 255,
                            green: g / 255,
                            blue: b / 255,
                            alpha: 1.0)
    }
    
    static func colorFromHex(_ Hex: UInt32) -> UIColor {
        return UIColor.init(red: CGFloat((Hex & 0xFF0000) >> 16) / 255.0,
                            green: CGFloat((Hex & 0xFF00) >> 8) / 255.0,
                            blue: CGFloat((Hex & 0xFF)) / 255.0,
                            alpha: 1.0)
    }
    
    /// 普通字体颜色
    open class var textColor: UIColor {
        
        get {
            return UIColor.lightGray
        }
    }
    
    /// 标题字体颜色
    open class var titleTextColor: UIColor {
        
        get {
            return UIColor.darkGray
        }
    }
    
    
    
    
    /// 随机色
    ///
    /// - Returns: 随机的颜色
    class func randomColor() -> UIColor {
        
        let r = CGFloat(arc4random() % 256) / 255.0
        let g = CGFloat(arc4random() % 256) / 255.0
        let b = CGFloat(arc4random() % 256) / 255.0
        
        return UIColor(red: r, green: g, blue: b, alpha: 1.0)
    }
    
}

//判断ipone x
extension UIDevice {
    public func isIphoneX() -> Bool {
        if UIScreen.main.bounds.height == 812 {
            return true
        }
        
        return false
    }
}
extension String {
    
    /// DocumentDirectory 路径
    ///
    /// - Parameter fileName: fileName
    /// - Returns: DocumentDirectory 内文件路径
    static func appendDocmentDirectory(fileName: String) -> String? {
        
        let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        return (path as NSString).appendingPathComponent(fileName)
    }
    
    /// Caches 路径
    ///
    /// - Parameter fileName: fileName
    /// - Returns: Cacher 内文件路径
    static func appendCachesDirectory(fileName: String) -> String? {
        
        let path = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0]
        return (path as NSString).appendingPathComponent(fileName)
    }
    
    /// Tmp 路径
    ///
    /// - Parameter fileName: fileName
    /// - Returns: Tmp 内文件路径
    static func appendTmpDirectory(fileName: String) -> String? {
        
        let path = NSTemporaryDirectory()
        return (path as NSString).appendingPathComponent(fileName)
    }
}
